/**
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，pro版只支持remixIcon图标，具体配置请查看vip群文档
 */
import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/vab/layouts'
/* 多级路由不需要缓存时可放开注释直接引入 用法component:VabEmptyLayout*/
/* import VabEmptyLayout from '@/vab/layouts/VabEmptyLayout' */
import { publicPath, routerMode } from '@/config'

Vue.use(VueRouter)
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login'),
    meta: {
      hidden: true,
    },
  },
  {
    path: '/register',
    component: () => import('@/views/register'),
    meta: {
      hidden: true,
    },
  },
  {
    path: '/403',
    name: '403',
    component: () => import('@/views/403'),
    meta: {
      hidden: true,
    },
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    meta: {
      hidden: true,
    },
  },
]

export const asyncRoutes = [
  {
    path: '/',
    name: 'Root',
    component: Layout,
    redirect: '/index',
    meta: {
      title: '控制台',
      icon: 'home-2-line',
    },
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/index'),
        meta: {
          title: '首页',
          icon: 'home-2-line',
          noClosable: true,
        },
      },
    ],
  },
  {
    // path会和children里边的path拼在一起组成路径
    path: '/vab',
    name: 'UserList',
    component: Layout,
    // 重定向的路径需要写详细（是两个path的组合）
    redirect: '/vab/user/userList',
    meta: {
      title: '用户管理',
      icon: 'contacts-fill',
    },
    children: [
      {
        path: 'user/userList',
        name: 'List',
        component: () => import('@/views/vab/user/userList'),
        meta: {
          title: '用户列表',
          icon: 'contacts-line',
          noClosable: true,
        },
      },
      {
        path: 'user/packer',
        name: 'Packer',
        component: () => import('@/views/vab/user/packer'),
        meta: {
          title: '钱包管理',
          icon: 'money-dollar-circle-line',
          noClosable: true,
        },
      },
      {
        path: 'user/identifile',
        name: 'identifile',
        component: () => import('@/views/vab/user/identifile'),
        meta: {
          title: '认证信息',
          icon: 'nurse-line',
          noClosable: true,
        },
      },
      {
        path: 'user/ticket',
        name: 'Ticket',
        component: () => import('@/views/vab/user/ticket'),
        meta: {
          title: '罚单管理',
          icon: 'skull-2-line',
          noClosable: true,
        },
      },
    ],
  },
  {
    // path会和children里边的path拼在一起组成路径
    path: '/vab',
    name: 'Orders',
    component: Layout,
    // 重定向的路径需要写详细（是两个path的组合）
    redirect: '/vab/table/order',
    meta: {
      title: '订单管理',
      icon: 'currency-fill',
    },
    children: [
      {
        path: 'table/order',
        name: 'Order',
        component: () => import('@/views/vab/table/order'),
        meta: {
          title: '订单管理',
          icon: 'currency-fill',
          noClosable: true,
        },
      },
      {
        path: 'table/routes',
        name: 'Routes',
        component: () => import('@/views/vab/table/routes'),
        meta: {
          title: '订单轨迹',
          icon: 'attachment-line',
          noClosable: true,
        },
      },
    ],
  },
  {
    // path会和children里边的path拼在一起组成路径
    path: '/vab',
    name: 'CarAdd',
    component: Layout,
    // 重定向的路径需要写详细（是两个path的组合）
    redirect: '/vab/car/carAdd',
    meta: {
      title: '车辆管理',
      icon: 'taxi-fill',
    },
    children: [
      {
        path: 'car/carAdd',
        name: 'Add',
        component: () => import('@/views/vab/car/carAdd'),
        meta: {
          title: '添加车辆',
          icon: 'contacts-line',
          noClosable: true,
        },
      },
      {
        path: 'car/carListes',
        name: 'carListes',
        component: () => import('@/views/vab/car/carListes'),
        meta: {
          title: '车辆列表',
          icon: 'money-dollar-circle-line',
          noClosable: true,
        },
      },
      {
        path: 'car/carFen',
        name: 'carFen',
        component: () => import('@/views/vab/car/carFen'),
        meta: {
          title: '车辆分布',
          icon: 'nurse-line',
          noClosable: true,
        },
      },
    ],
  },
  {
    // path会和children里边的path拼在一起组成路径
    path: '/vab',
    name: 'Makes',
    component: Layout,
    // 重定向的路径需要写详细（是两个path的组合）
    redirect: '/vab/make/applay',
    meta: {
      title: '维修管理',
      icon: 'contacts-fill',
    },
    children: [
      {
        path: 'make/applay',
        name: 'Applay',
        component: () => import('@/views/vab/make/applay'),
        meta: {
          title: '申请增加还车点',
          icon: 'contacts-line',
          noClosable: true,
        },
      },
      {
        path: 'make/require',
        name: 'Require',
        component: () => import('@/views/vab/make/require'),
        meta: {
          title: '问题反馈',
          icon: 'money-dollar-circle-line',
          noClosable: true,
        },
      },
      {
        path: 'make/make',
        name: 'make',
        component: () => import('@/views/vab/make/make'),
        meta: {
          title: '用户维修',
          icon: 'nurse-line',
          noClosable: true,
        },
      },
      {
        path: 'make/woker',
        name: 'Woker',
        component: () => import('@/views/vab/make/woker'),
        meta: {
          title: '工单管理',
          icon: 'skull-2-line',
          noClosable: true,
        },
      },
    ],
  },
  {
    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    // path会和children里边的path拼在一起组成路径
    path: '/vab',
    name: 'Message',
    component: Layout,
    // 重定向的路径需要写详细（是两个path的组合）
    redirect: '/vab/sell/messages/list',
    meta: {
      title: '营销活动',
      icon: 'emotion-laugh-fill',
    },
    children: [
      {
        path: 'sell/messages/list',
        name: 'Messages',
        component: () => import('@/views/vab/sell/messages/list'),
        redirect: '/vab/sell/messages/list',
        meta: {
          title: '短信群发',
          icon: 'contacts-line',
          // noClosable: true,
          children: [
            {
              path: 'list',
              name: 'List',
              component: () => import('@/views/vab/sell/messages/list'),
              meta: {
                title: '群发短信列表',
                noClosable: true,
              },
            },
            {
              path: 'remind',
              name: 'Remind',
              component: () => import('@/views/vab/sell/messages/remind'),
              meta: {
                title: '群发短信提醒',
                noClosable: true,
              },
            },
          ],
        },
      },
      {
        path: 'sell/money',
        name: 'Money',
        component: () => import('@/views/vab/sell/money'),
        meta: {
          title: '优惠券管理',
          icon: 'money-dollar-circle-line',
          noClosable: true,
        },
      },
      {
        path: 'sell/invite',
        name: 'Invite',
        component: () => import('@/views/vab/sell/invite'),
        meta: {
          title: '邀请新用户',
          icon: 'nurse-line',
          noClosable: true,
        },
      },
      {
        path: 'sell/free',
        name: 'Free',
        component: () => import('@/views/vab/sell/free'),
        meta: {
          title: '免押金卡',
          icon: 'skull-2-line',
          noClosable: true,
        },
      },
      {
        path: 'sell/recharge',
        name: 'Recharge',
        component: () => import('@/views/vab/sell/recharge'),
        meta: {
          title: '充值管理',
          icon: 'skull-2-line',
          noClosable: true,
        },
      },
      {
        path: 'sell/cycling',
        name: 'Cycling',
        component: () => import('@/views/vab/sell/cycling'),
        meta: {
          title: '骑行卡管理',
          icon: 'skull-2-line',
          noClosable: true,
        },
      },
    ],
  },
  {
    // path会和children里边的path拼在一起组成路径
    path: '/vab',
    name: 'infoM',
    component: Layout,
    // 重定向的路径需要写详细（是两个path的组合）
    redirect: '/vab/infoMessage/gongGao',
    meta: {
      title: '通知公告',
      icon: 'currency-fill',
    },
    children: [
      {
        path: 'infoMessage/gongGao',
        name: 'GongGao',
        component: () => import('@/views/vab/infoMessage/gongGao'),
        meta: {
          title: '公告管理',
          icon: 'currency-fill',
          noClosable: true,
        },
      },
      {
        path: 'infoMessage/ad',
        name: 'AD',
        component: () => import('@/views/vab/infoMessage/ad'),
        meta: {
          title: '广告管理',
          icon: 'attachment-line',
          noClosable: true,
        },
      },
    ],
  },
  {
    // path会和children里边的path拼在一起组成路径
    path: '/vab',
    name: 'Area',
    component: Layout,
    // 重定向的路径需要写详细（是两个path的组合）
    redirect: '/vab/area/areaList',
    meta: {
      title: '区域管理',
      icon: 'contacts-fill',
    },
    children: [
      {
        path: 'area/areaList',
        name: 'AreaList',
        component: () => import('@/views/vab/area/areaList'),
        meta: {
          title: '区域列表',
          icon: 'contacts-line',
          noClosable: true,
        },
      },
      {
        path: 'area/areaAdd',
        name: 'AreaAdd',
        component: () => import('@/views/vab/area/areaAdd'),
        meta: {
          title: '区域添加',
          icon: 'money-dollar-circle-line',
          noClosable: true,
        },
      },
      {
        path: 'area/areaPack',
        name: 'AreaPack',
        component: () => import('@/views/vab/area/areaPack'),
        meta: {
          title: '停车点管理',
          icon: 'skull-2-line',
          noClosable: true,
        },
      },
      {
        path: 'area/areaG',
        name: 'AreaG',
        component: () => import('@/views/vab/area/areaG'),
        meta: {
          title: '区域配置管理',
          icon: 'nurse-line',
          noClosable: true,
        },
      },
    ],
  },
  {
    // path会和children里边的path拼在一起组成路径
    path: '/vab',
    name: 'Moneys',
    component: Layout,
    // 重定向的路径需要写详细（是两个path的组合）
    redirect: '/vab/moneys/moneyCd',
    meta: {
      title: '资金管理',
      icon: 'taxi-fill',
    },
    children: [
      {
        path: 'moneys/moneyCd',
        name: 'MoneyC',
        component: () => import('@/views/vab/moneys/moneyCd'),
        meta: {
          title: '充值管理',
          icon: 'nurse-line',
          noClosable: true,
        },
      },
      {
        path: 'moneys/moneyG',
        name: 'MoneyG',
        component: () => import('@/views/vab/moneys/moneyG'),
        meta: {
          title: '收益管理',
          icon: 'contacts-line',
          noClosable: true,
        },
      },
      {
        path: 'moneys/moneyY',
        name: 'MoneyY',
        component: () => import('@/views/vab/moneys/moneyY'),
        meta: {
          title: '押金管理',
          icon: 'money-dollar-circle-line',
          noClosable: true,
        },
      },
    ],
  },
  {
    path: '/vab',
    name: 'People',
    component: Layout,
    redirect: '/vab/people/peopleA',
    meta: {
      title: '地勤人员',
      // icon: 'apps-line',
      // roles: ['admin'],
    },
    children: [
      {
        path: 'people/peopleA',
        name: 'peopleA',
        component: () => import('@/views/vab/people/peopleA'),
        meta: {
          title: '地勤人员',
          icon: 'shopping-cart-line',
          // badge: 'Hot',
        },
      },
    ],
  },
  // {
  //   path: '/vab',
  //   name: 'People',
  //   component: Layout,
  //   redirect: '/vab/people/peopleA',
  //   meta: {
  //     title: '地勤人员',
  //   },
  //   chileren: [
  //     {
  //       path: 'people/peopleA',
  //       name: 'peopleA',
  //       component: () => import('@/views/vab/people/peopleA'),
  //       meta: {
  //         title: '地勤人员',
  //         icon: 'nurse-line',
  //         noClosable: true,
  //       },
  //     },
  //   ],
  // },
  {
    // path会和children里边的path拼在一起组成路径
    path: '/vab',
    name: 'Admins',
    component: Layout,
    // 重定向的路径需要写详细（是两个path的组合）
    redirect: '/vab/admins/adminList',
    meta: {
      title: '管理员管理',
      icon: 'currency-fill',
    },
    children: [
      {
        path: 'admins/adminList',
        name: 'AdminList',
        component: () => import('@/views/vab/admins/adminList'),
        meta: {
          title: '管理员列表',
          icon: 'currency-fill',
          noClosable: true,
        },
      },
      {
        path: 'admins/adminAdd',
        name: 'AdminAdd',
        component: () => import('@/views/vab/admins/adminAdd'),
        meta: {
          title: '添加管理员',
          icon: 'attachment-line',
          noClosable: true,
        },
      },
    ],
  },
  {
    path: '/vab',
    name: 'Roles',
    component: Layout,
    redirect: '/vab/roles/roleList',
    meta: {
      title: '角色管理',
      // icon: 'apps-line',
      // roles: ['admin'],
    },
    children: [
      {
        path: 'roles/roleList',
        name: 'RolesList',
        component: () => import('@/views/vab/roles/roleList'),
        meta: {
          title: '角色列表',
          icon: 'shopping-cart-line',
          // badge: 'Hot',
        },
      },
    ],
  },

  {
    // path会和children里边的path拼在一起组成路径
    path: '/vab',
    name: 'Business',
    component: Layout,
    // 重定向的路径需要写详细（是两个path的组合）
    redirect: '/vab/business/businessList',
    meta: {
      title: '商户管理',
      icon: 'currency-fill',
    },
    children: [
      {
        path: 'business/businessList',
        name: 'BusinessList',
        component: () => import('@/views/vab/business/businessList'),
        meta: {
          title: '商户列表',
          icon: 'currency-fill',
          noClosable: true,
        },
      },
      {
        path: 'business/businessPZ',
        name: 'BusinessPZ',
        component: () => import('@/views/vab/business/businessPZ'),
        meta: {
          title: '商户配置',
          icon: 'attachment-line',
          noClosable: true,
        },
      },
    ],
  },
  {
    path: '*',
    redirect: '/404',
    meta: {
      hidden: true,
    },
  },
]

const router = createRouter()

export function resetRouter(routes = constantRoutes) {
  router.matcher = createRouter(routes).matcher
}

function createRouter(routes = constantRoutes) {
  return new VueRouter({
    base: publicPath,
    mode: routerMode,
    scrollBehavior: () => ({
      y: 0,
    }),
    routes: routes,
  })
}

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch((err) => err)
}

export default router
